/*
 * EquilibriumProblem2.cpp
 *
 *  Created on: 27 Jul 2011
 *      Author: Allan
 */

#include "EquilibriumProblem2.h"

EquilibriumProblem2::EquilibriumProblem2(const MatrixXd& uei, const MatrixXd& alpha, const VectorXd& hj, const VectorXd& ln_a, const VectorXd& ln_Ke) :
N(ln_a.rows()), Ne(ln_Ke.rows()), Nj(hj.rows()), uei(uei), alpha(alpha), hj(hj), ln_a(ln_a), ln_Ke(ln_Ke)
{}

EquilibriumProblem2::~EquilibriumProblem2()
{}

void EquilibriumProblem2::Function(const VectorXd& n, VectorXd& F)
{
	// Compute the residual vector Fe
	F.segment(0, Ne) = uei * ln_a - ln_Ke;
	
	// Compute the residual vector Fj
	F.segment(Ne, Nj) = alpha * n - hj;
}

void EquilibriumProblem2::Jacobian(const VectorXd& n, MatrixXd& J)
{
	// Compute the block Jacobian matrix Jei
	J.block(0, 0, Ne, N) = uei * n.asDiagonal().inverse();
	
	// Compute the block Jacobian matrix Jji
	J.block(Ne, 0, Nj, N) = alpha;
}
